package com.totoro.tygeneratedragonblock.enums;

import com.totoro.tygeneratedragonblock.constants.ConditionConst;
import com.totoro.tygeneratedragonblock.executor.condition.ConditionExecutor;
import com.totoro.tygeneratedragonblock.executor.condition.impl.DefaultConditionExecutor;
import com.totoro.tygeneratedragonblock.executor.condition.impl.NotPermissionConditionExecutor;
import com.totoro.tygeneratedragonblock.executor.condition.impl.PapiConditionExecutor;
import com.totoro.tygeneratedragonblock.executor.condition.impl.PermissionConditionExecutor;

public enum ConditionEnum {
    PAPI_CONDITION(ConditionConst.PAPI_CONDITION, new PapiConditionExecutor()),
    PERMISSION_CONDITION(ConditionConst.PERMISSION_CONDITION, new PermissionConditionExecutor()),
    NOT_PERMISSION_CONDITION(ConditionConst.NOT_PERMISSION_CONDITION, new NotPermissionConditionExecutor()),;

    private final String conditionIdentifier;
    private final ConditionExecutor conditionExecutor;

    public static ConditionEnum getValue(String conditionText) {
        ConditionEnum[] values = values();
        for (ConditionEnum value : values) {
            if (conditionText.startsWith(value.conditionIdentifier)) {
                return value;
            }
        }
        return null;
    }

    public static ConditionExecutor getExecutor(String conditionText) {
        ConditionEnum conditionEnum = getValue(conditionText);
        if(null != conditionEnum) {
            return conditionEnum.conditionExecutor;
        }
        return new DefaultConditionExecutor();
    }

    ConditionEnum(String conditionIdentifier, ConditionExecutor conditionExecutor) {
        this.conditionIdentifier = conditionIdentifier;
        this.conditionExecutor = conditionExecutor;
    }
}
